package com.example.myapplication2.aroutermodule

import android.content.Context
import com.alibaba.android.arouter.facade.Postcard
import com.alibaba.android.arouter.facade.annotation.Interceptor
import com.alibaba.android.arouter.facade.callback.InterceptorCallback
import com.alibaba.android.arouter.facade.template.IInterceptor
import com.example.base_libs.moduleA
import com.example.base_libs.moduleB


// 首先是设置权限，然后还有权限的优先级
@Interceptor(priority = 1, name = "登陆检查拦截器")
class LoginInterceptorImpl : IInterceptor {

    override fun init(context: Context?) {

    }

    override fun process(postcard: Postcard?, callback: InterceptorCallback?) {
        val path = postcard!!.path
//        if (isLogin()) {
            when (path) {
                // 需要登录的页面就拦截下来
                moduleA, moduleB -> {
                    // 需要拦截的是 onInterrupt
                    callback?.onInterrupt(null)
                }
                else -> {
                    // 不需要拦截的是 onContinue
                    callback?.onContinue(postcard)
                }
            }
//        } else {
//            callback?.onInterrupt(null)
//        }


    }


    fun isLogin(): Boolean {
        return false
    }

}